﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sekretar.DataLayer;

namespace Sekretar.Repository
{
    public class RMesto : BaseRepository, InterfaceRepository<Mesto>
    {
        public IQueryable<Mesto> VratiSve()
        {
            dc = new SekretarDataContext();
            return dc.Mestos;
        }

        public Mesto Nov()
        {
            this.jeNov = true;

            Mesto n = new Mesto();

            n.OpstinaId = 1;
            n.DrzavaId = 1;
            n.Status = true;
            n.KorisnikId = Common.Properties.Settings.Default.KorisnikId;
            n.DatumRada = Common.Tools.SqlFunkcije.VratiTrenutnoVreme();

            return n;
        }

        public Mesto Izmeni(int id)
        {
            return dc.Mestos.SingleOrDefault(c => c.MestoId == id);
        }

        public int Snimi(Mesto t)
        {
            if (this.jeNov) dc.Mestos.InsertOnSubmit(t);
            dc.SubmitChanges();
            return t.MestoId;
        }

        public void Brisi(int id)
        {
            dc.Mestos.DeleteOnSubmit(dc.Mestos.SingleOrDefault(c => c.MestoId == id));
            dc.SubmitChanges();       
        }

        public IQueryable<Mesto> VratiSveAktivne()
        {
            dc = new DataLayer.SekretarDataContext();
            return dc.Mestos.Where(c => c.Status == true);
        }
    }
}
